<template>
  <el-dialog
    :title="dialogTitle"
    class="training_dialog gl_dialog_TitleLine gl_dl_footer"
    :visible.sync="dialogVisible"
    width="1248px"
  >
    <div v-loading="dialogLoading">
      <!-- 页面列表 -->
      <template v-if="dto.length">
        <div v-for="(item, index) in dto" :key="index" class="flex_model">
          <div v-show="item.isOfficial" class="flex_official">官</div>
          <div class="flex_row">
            <div v-for="(jtem, jndex) in item.levels" :key="jndex" class="flex_col gl_clear">
              <div class="flex_col_title gl_fl">
                <span>{{ traningTxtUppercase[jtem.level - 1] }}级科目</span>
              </div>
              <el-radio-group v-model="item.radios[jndex].radios" style="height: 100%; width: calc(100% - 32px);">
                <div class="flex_col_content" style="width: calc(100% - 32px);overflow:auto">
                  <el-radio v-for="(ntem, ndex) in jtem.templateParts" :key="ndex" :label="ntem.id">
                    <span style="display:inline-block; max-width: 155px" class="gl_ellipsis" :title="ntem.name">{{ ntem.name }}</span>
                  </el-radio>
                </div>
              </el-radio-group>
            </div>
            <!-- 必报 -->
            <template v-if="dialogMode === 'Exam'">
              <div class="flex_col gl_clear">
                <div class="flex_col_title gl_fl">
                  <span>必报科目</span>
                </div>
                <el-radio-group v-model="item.isEntryRequired" style="height:100%">
                  <div class="flex_col_content">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                  </div>
                </el-radio-group>
              </div>
            </template>
          </div>
          <div class="flex_control">
            <div class="gl_mb_10">
              <span class="flce_control_label">会员价</span>
              <el-input-number v-model="item.memberPrice" :min="0" :max="21474836" :precision="2" style="width: 150px" size="medium" :controls="false" />
            </div>
            <div class="gl_mb_10">
              <span class="flce_control_label">非会员价</span>
              <el-input-number v-model="item.nonMemberPrice" :min="0" :max="21474836" :precision="2" style="width: 150px" size="medium" :controls="false" />
            </div>
            <div>
              <el-button style="width: 100%" size="medium" type="primary" @click="submitDialog(item)">提交</el-button>
            </div>
          </div>

        </div>
      </template>
      <template v-else>
        <div class="flex_model no_data">
          暂无可导入的模板
        </div>
      </template>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    dialogMode: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      traningTxtUppercase: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十'],
      dialogTitle: '',
      dialogVisible: false,
      dialogLoading: false,
      dto: []
    };
  },
  methods: {
    // 打开弹窗
    openDialog (options) {
      this.dialogTitle = options.title;
      if (options.dto) {
        this.dto = options.dto.map(item => {
          item.radios = item.levels.map(jtem => {
            return {
              level: jtem.level,
              radios: ''
            };
          });
          item.memberPrice = 0;
          item.nonMemberPrice = 0;
          item.isEntryRequired = '';
          return item;
        });
      }
      this.dialogVisible = true;
    },
    // 关闭弹窗
    closeDialog () {
      this.resetDialog();
      this.dialogVisible = false;
    },
    changeLoading (val) {
      this.dialogLoading = val;
    },
    // 确认弹窗内的信息
    submitDialog (data) {
      for (let i = 0; i < data.radios.length; i++) {
        const item = data.radios[i];
        if (item.radios === '') {
          this.$message({
            message: `${this.traningTxtUppercase[item.level - 1]}级科目中未选择科目`,
            type: 'warning',
            showClose: true
          });
          return;
        }
      }

      if (this.dialogMode === 'Exam' && data.isEntryRequired === '') {
        this.$message({
          message: `请选择科目是否必报`,
          type: 'warning',
          showClose: true
        });
        return;
      }
      this.dialogLoading = true;
      this.$emit('onSubmit', data);
    },
    // 重置弹窗数据
    resetDialog () {
      this.dto = [];
    }
  }
};
</script>

<style lang="scss" scoped>
  .flex_model {
    position: relative;
    min-height: 138px;
    margin-bottom: 28px;
  }
  .flex_official {
    box-sizing: border-box;
    position: absolute;
    top: 50%;
    left: 0;
    width: 22px;
    height: 22px;
    margin-top: -11px;
    font-size: 12px;
    line-height: 22px;
    text-align: center;
    color: #1990ff;
    border: 1px solid #1990ff;
    border-radius: 50%;
    background-color: #fff;
  }
  .flex_row {
    box-sizing: border-box;
    width: 942px;
    margin-left: 34px;
    min-height: 138px;
    display: flex;
    border-radius: 8px;
    border: 1px solid #d9d9d9;
    overflow: hidden;
  }
  .flex_col {
    flex: 1;
  }
  .flex_control {
    position: absolute;
    top: 50%;
    left: 976px;
    margin-top: -64px;
    padding: 0 0 0 16px;
  }
  .flce_control_label {
    width: 60px;
    display: inline-block;
    vertical-align: middle;
    font-size: 14px;
    font-weight: 400;
    color: #000;
    line-height: 18px;
  }
  .flex_col_title {
    box-sizing: border-box;
    width: 32px;
    padding: 0 9px;
    height: 100%;
    font-size: 14px;
    line-height: 18px;
    color: rgba(0, 0, 0, 0.65);
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #E8F4FF;
  }
  .flex_col_content {
    box-sizing: border-box;
    height: 100%;
    width: 100%;
    padding: 10px 0 10px 30px;
    font-size: 14px;
    line-height: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    color: rgba(0, 0, 0, 0.65);
  }
</style>
